package com.wut.clock.controller;

import com.wut.clock.common.api.CommonPage;
import com.wut.clock.common.api.CommonResult;
import com.wut.clock.service.IMessageService;
import com.wut.clock.vo.admin.MessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZYH
 * @unit D9Lab
 * @description 消息管理
 * @date 2022/6/1 16:59
 */
@Api(value = "消息管理",tags = {"消息管理"})
@RestController
@RequestMapping("/message")
@RequiredArgsConstructor
public class MessageController {

    private final IMessageService messageService;

    @ApiOperation("查看消息列表")
    @GetMapping("/getMessageList")
    @RequiresPermissions("am:message:query")
    public CommonResult<CommonPage<MessageVo>> getMessageList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                              @RequestParam(defaultValue = "10") Integer pageSize,
                                                              @RequestParam(required = false) Integer userId,
                                                              @RequestParam(required = false) Integer fromUserId,
                                                              @RequestParam(required = false) Integer targetType,
                                                              @RequestParam(required = false) Integer type,
                                                              @RequestParam(required = false) String content,
                                                              @RequestParam(required = false) Integer status) {
        List<MessageVo> messageList = messageService.getMessageList(pageNum,pageSize,userId,fromUserId,targetType,type,content,status);
        if(messageList.size()>0){
            return CommonResult.success(CommonPage.restPage(messageList),"查看消息列表成功");
        }
        return CommonResult.failed("消息列表不存在");
    }

}
